<?php
/**
 * 公共函數庫
 * 
 * @author 雅典娜之子
 * @version SVN:$Id: common.func.php 2010-04-24
 */
!defined('ACCESSING') && exit('Forbidden');
/**
 * DropSession：清空SESSION。
 */
function DropSession($key)
{
	unset($_SESSION[$key]);
    unset($_SESSION[$key."__ckMd5"]);
}

//獲取SESSION訊息
function GetSession($key)
{
    global $BASE;
    if(!isset($_SESSION[$key]) || !isset($_SESSION[$key."__ckMd5"]))
    {
        return 0;
    }
    else
    {
        if($_SESSION[$key."__ckMd5"] != md5($BASE['encode_key'].$_SESSION[$key]))
        {
            return 0;
        }
        else
        {
            return $_SESSION[$key];
        }
    }
}

//過濾危險HTML
function SplaceStr($str)
{
    $farr = array(
        "/\s /", //過濾多餘的空白
        "/<(\/?)(script|i?frame|style|html|body|title|link|meta|\?|\%)([^>]*?)>/is",
        "/(<[^>]*)on[a-zA-Z] \s*=([^>]*>)/is", //過濾javascript的on事件

    );
    $tarr = array(
    " ",
    "", //如果要直接清除不安全的標記，這裡可以留空
    "",
    );
    $str = preg_replace( $farr,$tarr,$str);
    return $str;
}

//JS彈窗
function ShowMsg($str,$url='',$type=0)
{
    switch ($type)
    {
        case 0:
            echo "<script type='text/javascript'>alert('$str');</script>";
            break;
        case 1:
            echo "<script type='text/javascript'>alert('$str');history.back();</script>";
            break;
        case 2:
            echo "<script type='text/javascript'>alert('$str');location.href=('$url');</script>";
            break;
		case 3:
            echo "<script type='text/javascript'>alert('$str');parent.location.href=('$url');</script>";
            break;
    }
}
?>
